#ifndef MAC_LABEL_H
#define MAC_LABEL_H

#ifndef WIN32
    #define FILE_ANY_ACCESS (1)
    #define FILE_WRITE_ACCESS (2)
    #ifndef CTL_CODE
        #define CTL_CODE(a, b, c, d)   (((a) << 16) | (unsigned int )(b))
    #endif
#endif

#define FILE_DEVICE_SECMODCTL  0x00654322
#define DRVSECMODCTL_IOCTL_INDEX 123

#define XSECMODCTL_READ_AUDIT CTL_CODE(FILE_DEVICE_SECMODCTL, DRVSECMODCTL_IOCTL_INDEX + 27, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define XSECMODCTL_LOAD_WL_POLICY CTL_CODE(FILE_DEVICE_SECMODCTL, DRVSECMODCTL_IOCTL_INDEX + 28, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define XSECMODCTL_LOAD_MAC_OBJECT_LIST CTL_CODE(FILE_DEVICE_SECMODCTL, DRVSECMODCTL_IOCTL_INDEX + 29, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define XSECMODCTL_LOAD_MAC_SUBJECT_LIST CTL_CODE(FILE_DEVICE_SECMODCTL, DRVSECMODCTL_IOCTL_INDEX + 30, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define XSECMODCTL_SET_CONFIG CTL_CODE(FILE_DEVICE_SECMODCTL, DRVSECMODCTL_IOCTL_INDEX + 31, METHOD_BUFFERED, FILE_ANY_ACCESS)

enum dtype_mac_label
{
	TYPE(MAC_LABEL)=0x4220,
};

enum subtype_mac_label
{
	SUBTYPE(MAC_LABEL,LABEL)=0x01,
	SUBTYPE(MAC_LABEL,CTL_HEAD),
	SUBTYPE(MAC_LABEL,SUBJECT),
	SUBTYPE(MAC_LABEL,OBJECT),
	SUBTYPE(MAC_LABEL,AUDIT_HEAD),
	SUBTYPE(MAC_LABEL,FILE_EVENT)
};

typedef struct mac_label_ctl_head
{
    unsigned int uCode;         // -- 消息码
    unsigned int wParam;        // -- 扩展参数
    unsigned int lParam;        // -- 扩展参数
    unsigned int cntLen;        // -- 消息内容长度，不包括头部
}__attribute__((packed)) RECORD(MAC_LABEL,CTL_HEAD);
typedef RECORD(MAC_LABEL,CTL_HEAD) CTL_HDR;


typedef struct mac_label_label
{
	unsigned short category;
	unsigned char sec_label;
    unsigned char inte_label;
}__attribute__((packed)) RECORD(MAC_LABEL,LABEL); 

typedef struct mac_label_subject
{
	char name[64];
    int user_id;
    RECORD(MAC_LABEL,LABEL) label;
}__attribute__((packed)) RECORD(MAC_LABEL,SUBJECT);

typedef RECORD(MAC_LABEL,SUBJECT) USER_LABEL;

typedef struct mac_label_object
{
	unsigned char object_uuid[32];
    RECORD(MAC_LABEL,LABEL) label;
}__attribute__((packed)) RECORD(MAC_LABEL,OBJECT);

typedef RECORD(MAC_LABEL,OBJECT) FILE_LABEL;


#define __ADT_TYPE_FILE (1)

#define __OP_TYPE_FILE_CONTENT (1)

#define __ADT_MAGIC (0x12345678)

#define __CTL_RESP_OK (0)

#define __CTL_RESP_FAILED (-1)


typedef struct mac_label_audit_head
{
	unsigned magic;
    int type;
    unsigned short length;
}__attribute__((packed)) RECORD(MAC_LABEL,AUDIT_HEAD);

typedef RECORD(MAC_LABEL,AUDIT_HEAD) ADT_HDR;

typedef struct mac_label_file_event
{
    unsigned char opType;
	int uid;
    int nameLen;
    char * fileName;
}__attribute__((packed)) RECORD(MAC_LABEL,FILE_EVENT);

typedef RECORD(MAC_LABEL,FILE_EVENT) ADT_FILE_EVENT;

typedef struct __IOCTL_PACKET
{
    CTL_HDR hdr;
    unsigned char inputBuffer[0];
}__attribute__((packed)) IOCTL_PACKET;

typedef struct __ADT_COMMON
{
    ADT_HDR hdr;
    char cnt[0];
}__attribute__((packed)) ADT_COMMON;

typedef struct tagconfig_data
{
    int bWhiteListEnable;
    int bWatchFileEvent;
    int bAclEnable;
    char watchFolder[512];
    char aclFolder[512];
}__attribute__((packed)) CONFIG_DATA;

#endif
